package top.shiyiri.exer;

import java.util.List;

/**
 * @author Aunean
 * @date 2022/1/8
 */
/*
创建 DAO 类的对象， 分别调用其 save、get、update、list、delete 方
法来操作 User 对象，
 */
public class DaoTest {

    public static void main(String[] args) {
        DAO<User> userDAO = new DAO<>();

        userDAO.save("1001", new User(1001, 18, "Tom"));
        userDAO.save("1002", new User(1001, 19, "Jerry"));
        userDAO.save("1001", new User(1001, 99, "Tom"));

        List<User> list = userDAO.list();
        System.out.println(list);//[User{id=1001, age=19, name='Jerry'}, User{id=1001, age=99, name='Tom'}]

        User user = userDAO.get("1001");
        System.out.println(user);//User{id=1001, age=99, name='Tom'}

        userDAO.update("1002", new User(1003, 22, "TOM"));
        System.out.println(userDAO.list());//[User{id=1003, age=22, name='TOM'}, User{id=1001, age=99, name='Tom'}]

        userDAO.delete("1003");
        System.out.println(userDAO.list());//[User{id=1003, age=22, name='TOM'}, User{id=1001, age=99, name='Tom'}]

        userDAO.delete("1002");
        System.out.println(userDAO.list());//[User{id=1001, age=99, name='Tom'}]
    }
}
